﻿#region Copyright and License Notice
// Copyright (C)2010-2016 - Rob Levine and other contributors
// http://configgen.codeplex.com
// 
// This file is part of ConfigGen.
// 
// ConfigGen is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// ConfigGen is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License and 
// the GNU Lesser General Public License along with ConfigGen.  
// If not, see <http://www.gnu.org/licenses/>
#endregion

using System;
using ConfigGen.Utilities.Extensions.System;
using NUnit.Framework;

namespace ConfigGen.Utilities.Tests.Extensions
{
    [TestFixture]
    public class ArrayExtensionsTests
    {
        [Test]
        public void IsNullOrEmpty001_Null()
        {
            byte[] byteArray1 = null;

            Assert.IsTrue(byteArray1.IsNullOrEmpty());
        }

        [Test]
        public void IsNullOrEmpty002_Empty()
        {
            byte[] byteArray1 = new byte[0];

            Assert.IsTrue(byteArray1.IsNullOrEmpty());
        }

        [Test]
        public void IsNullOrEmpty003_NonNullNonEmpty()
        {
            byte[] byteArray1 = new byte[] { 0x1 };

            Assert.IsFalse(byteArray1.IsNullOrEmpty());
        }
        [Test]
        public void IsEqualTo001_SameReference_AreEqual()
        {
            byte[] byteArray1 = new byte[0];

            Assert.IsTrue(byteArray1.IsEqualTo(byteArray1));
        }

        [Test]
        public void IsEqualTo002_FirstNull_NotEqual()
        {
            byte[] byteArray1 = null;
            byte[] byteArray2 = new byte[0];

            Assert.IsFalse(byteArray1.IsEqualTo(byteArray2));
        }

        [Test]
        public void IsEqualTo003_SecondNull_NotEqual()
        {
            byte[] byteArray1 = new byte[0];
            byte[] byteArray2 = null;

            Assert.IsFalse(byteArray1.IsEqualTo(byteArray2));
        }

        [Test]
        public void IsEqualTo004_BothNull_AreEqual()
        {
            byte[] byteArray1 = null;
            byte[] byteArray2 = null;

            Assert.IsTrue(byteArray1.IsEqualTo(byteArray2));
        }

        [Test]
        public void IsEqualTo005_DifferentLength_NotEqual()
        {
            var byteArray1 = new byte[] { 255, 127, 00 };
            var byteArray2 = new byte[] { 255, 127 }; ;

            Assert.IsFalse(byteArray1.IsEqualTo(byteArray2));
        }

        [Test]
        public void IsEqualTo006_DifferentContents_NotEqual()
        {
            var byteArray1 = new byte[] { 255, 127, 00 };
            var byteArray2 = new byte[] { 255, 127, 01 }; ;

            Assert.IsFalse(byteArray1.IsEqualTo(byteArray2));
        }

        [Test]
        public void IsEqualTo007_AreEqual()
        {
            var byteArray1 = new byte[] { 255, 127, 01 };
            var byteArray2 = new byte[] { 255, 127, 01 }; ;

            Assert.IsTrue(byteArray1.IsEqualTo(byteArray2));
        }

        [Test]
        public void IsCollectionOfNullOrEmpty001_NullArrayReturnsTrue()
        {
            object[] array = null;
            Assert.IsTrue(array.IsCollectionOfNullOrEmpty());
        }

        [Test]
        public void IsCollectionOfNullOrEmpty002_EmptyArrayReturnsTrue()
        {
            var array = new object[0];
            Assert.IsTrue(array.IsCollectionOfNullOrEmpty());
        }

        [Test]
        public void IsCollectionOfNullOrEmpty003_ArrayOfNullsReturnsTrue()
        {
            var array = new object[] {null, null, null};
            Assert.IsTrue(array.IsCollectionOfNullOrEmpty());
        }

        [Test]
        public void IsCollectionOfNullOrEmpty004_ArrayOfEmptyStringsReturnsTrue()
        {
            var array = new object[] { string.Empty, string.Empty, string.Empty };
            Assert.IsTrue(array.IsCollectionOfNullOrEmpty());
        }

        [Test]
        public void IsCollectionOfNullOrEmpty005_ArrayOfDBNullsReturnsTrue()
        {
            var array = new object[] { DBNull.Value, DBNull.Value, DBNull.Value };
            Assert.IsTrue(array.IsCollectionOfNullOrEmpty());
        }

        [Test]
        public void IsCollectionOfNullOrEmpty006()
        {
            var array = new object[] { DBNull.Value, "hello", DBNull.Value };
            Assert.IsFalse(array.IsCollectionOfNullOrEmpty());
        }
    }
}
